﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ProjectRoughWork
{
    class MenuComponent 
    {
        public MenuComponent()  
        {

        }

        public MenuComponent(Rectangle initBB, String initText, Texture2D initBgImage)
        {
            boundingBox = initBB;
            position = new Vector2(initBB.X, initBB.Y);
            drawBox = new Rectangle(0, 0, boundingBox.Width, boundingBox.Height);


            componentText = initText;
            backgroundImage = initBgImage;

            origin = new Vector2(boundingBox.Width / 2, boundingBox.Height / 2);

            textPosition = new Vector2(position.X - (origin.X)/2, position.Y);

            textColor = Color.Red;
        }

        public bool CheckIfClicked(int x, int y)
        {
            if (boundingBox.Contains(x, y))
            {
                return true;
            }

            return false;
        }

        public Color TextColor
        {
            get { return textColor; }
            set { textColor = value; }
        }

        public void Draw()
        {
            //Draw Code here

            
            SpriteBatch spriteBatch = Game1.GetSpriteBatch();
            SpriteFont font = Game1.GetSpriteFont();

            Vector2 textOrigin = font.MeasureString(componentText);
            textPosition = new Vector2(position.X - textOrigin.X/2/*(origin.X)/2*/, position.Y - textOrigin.Y/2);

            spriteBatch.Begin();

            spriteBatch.Draw(backgroundImage, position, drawBox, Color.White, 0f, origin, 1f, SpriteEffects.None, 0);
            spriteBatch.DrawString(font, componentText, textPosition, textColor);

            spriteBatch.End();
        }

        //Data Members

        Vector2 origin;
        Vector2 position;
        Vector2 textPosition;
        Rectangle boundingBox;
        Rectangle drawBox;

        String componentText;
        Color textColor;
        Texture2D backgroundImage;
        
    }
}
